﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Profile.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content2" ContentPlaceHolderID="contentPane" runat="server">
    
    <% if (WebApp.Controllers.ApplicationController.IsMe(ViewData))
       { %>
        <div id='update-status' class="tabControl">
            <script type="text/javascript">
                $(document).ready(function () {
                    $('#submit-new-status').click(function () {
                        // Params taken from http://daipratt.co.uk/using-fb-api-to-make-a-full-post-to-a-users-wall/
                        var params = {};
                        params['message'] = $('#input-new-status').val(); ;
                        if (params['message'] == '') return;

                        FB.api('/me/feed', 'post', params, function (response) {
                            if (!response || response.error) {
                                console.log('Error occured posting a message');
                            } else {
                                console.log('Post ID: ' + response.id);
                                location.reload();
                            }
                        });
                    });
                });



                function facebookReady() {
                    var accessToken = $("#authToken").val();

                }

            </script>
            Status:
            <textarea rows='2' cols='4' id='input-new-status'></textarea>
            <input type="button" id='submit-new-status' value='Post' />
        </div>
    <% } %>

    <%
        List<WebApp.Models.Post> posts = (List<WebApp.Models.Post>)ViewData["Model"];
        WebApp.Models.Photo photo;
        foreach (WebApp.Models.Post post in posts)
        {
    %>
    <div class="post">
        <ul>
            <%
            if (post.Type == "photo")
            {
                photo = post.Photo;
            %>
            <br />
            <li><a href="<%=post.Link %>">
                <img alt="<%=photo.Name %>" src="<%=photo.Picture %>" /></a>
                <%=photo.Name %>
            </li>
            <%
            }
            else if (post.Type == "status")
            {
            %>
            <br />
            <%=post.Message%> -- <%=post.Story%> -- posted by <%=post.From.Name %> <%=post.From.LastName %>
            <%
            } %>
        </ul>
    </div>
    <%
        }
    %>
</asp:Content>
